﻿Imports Clases
Public Class frmCajaRegistradora
    Public btn() As Button = {}
    Dim precioTotal As Decimal
    Public Sub cargarBotones()
        If miGestion.Productos.Count > 0 Then
            Array.Resize(btn, miGestion.Productos.Count)
            Dim x As Integer = 10
            Dim y As Integer = 20
            For i As Integer = 0 To btn.Length - 1
                btn(i) = New Button
                btn(i).Name = "btn" & i
                btn(i).BackgroundImage = miGestion.Productos(i).Foto
                btn(i).Location = New Point(50, y)
                btn(i).Size = New Size(90, 90)
                btn(i).Text = miGestion.Productos(i).Nombre
                btn(i).Tag = miGestion.Productos(i).Precio
                AddHandler btn(i).Click, AddressOf btnProducto_Click
                y += btn(i).Width + 5
            Next
            grbProductos.Controls.AddRange(btn)
        End If
    End Sub
    Public Sub frmCajaRegistradora_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        cargarBotones()

        ''FALTA: CONTROLAR ANCHOS Y ALTOS
        'If miGestion.Productos.Count > 0 Then
        '    Array.Resize(btn, miGestion.Productos.Count)
        '    Dim x As Integer = 10
        '    Dim y As Integer = 20
        '    For i As Integer = 0 To btn.Length - 1
        '        btn(i) = New Button
        '        btn(i).Name = "btn" & i
        '        btn(i).BackgroundImage = miGestion.Productos(i).Foto
        '        btn(i).Location = New Point(50, y)
        '        btn(i).Size = New Size(90, 90)
        '        btn(i).Text = miGestion.Productos(i).Nombre
        '        btn(i).Tag = miGestion.Productos(i).Precio
        '        AddHandler btn(i).Click, AddressOf btnProducto_Click
        '        y += btn(i).Width + 5
        '    Next
        '    grbProductos.Controls.AddRange(btn)
        'End If
    End Sub

    Private Sub btnProducto_Click(ByVal sender As Object, e As EventArgs)
        Dim boton As Button = sender
        lstVenta.Items.Add("1 " & boton.Text & " " & boton.Tag)
        precioTotal += boton.Tag
        lblTotal.Text = precioTotal
    End Sub

   
    Private Sub btnNuevosProductos_Click(sender As System.Object, e As System.EventArgs) Handles btnNuevosProductos.Click
        frmAñadirProductos.Show()
    End Sub

    Private Sub btnBorrarProductos_Click(sender As System.Object, e As System.EventArgs) Handles btnBorrarProductos.Click
        frmBorrarProductos.Show()
    End Sub

    Private Sub btnInicializarVenta_Click(sender As System.Object, e As System.EventArgs) Handles btnInicializarVenta.Click
        precioTotal = 0
        lstVenta.Items.Clear()
        lblTotal.Text = precioTotal
    End Sub
End Class
